package com.gwz.bus.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gwz.bus.domain.Goods;
import com.gwz.bus.service.GoodService;
import com.gwz.bus.vo.CustomerVo;
import com.gwz.bus.vo.GoodsVo;
import com.gwz.sys.utils.DataGridView;
import com.gwz.sys.utils.ResultObj;

@RestController
@RequestMapping("goods")
public class GoodsController {
	
	@Autowired
	private GoodService goodsService;
	
	@RequestMapping("loadAllGoods")
	public DataGridView loadAllGoods(GoodsVo goodsVo) {
		return goodsService.queryAllGoods(goodsVo);
	}
	
	@RequestMapping("addGoods")
	public ResultObj addGoods(GoodsVo goodsVo) {
		ResultObj resultObj = new ResultObj(200, "添加成功");
		try {
			goodsService.addGoods(goodsVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("添加失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("updateGoods")
	public ResultObj updateGoods(GoodsVo goodsVo) {
		ResultObj resultObj = new ResultObj(200, "修改成功");
		try {
			goodsService.updateGoods(goodsVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("修改失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("deleteGoods")
	public ResultObj deleteGoods(GoodsVo goodsVo) {
		ResultObj resultObj = new ResultObj(200, "删除成功");
		try {
			goodsService.deleteGoods(goodsVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("删除失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("batchDelete")
	public ResultObj batchDelete(GoodsVo goodsVo) {
		ResultObj resultObj = new ResultObj(200, "删除成功");
		try {
			goodsService.batchDelete(goodsVo);
			return resultObj;
		} catch (Exception e) {
			resultObj.setCode(-1);
			resultObj.setMsg("删除失败");
			e.printStackTrace();
			return resultObj;
		}
	}
	
	@RequestMapping("loadGoodsByProviderId")
	public List<Goods> loadGoodsByProviderId(Integer providerid){
		return goodsService.loadGoodsByProviderId(providerid);
	}
}
